<?php

namespace App\Kuafu\Pay\Model;

use App\Kuafu\Base\Model\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class PayCallbackLog extends BaseModel
{
    use HasFactory;

    protected $connection       = 'mysql';
    protected $table            = 'pay_callback_logs';
    protected $primaryKey       = 'id';
    public    $timestamps       = false;

    protected $fillable = [
        'payChannel',
        'serialNo',
        'requestData',
        'responseData',
        'createdAt'
    ];

    /**
     * 新增日志request
     * @param int $payChannel
     * @param string $serialNo
     * @param string $requestData
     * @return int
     */
    public static function addData(int $payChannel, string $serialNo, string $requestData): int
    {
        return self::query()->insertGetId([
            'payChannel'  => $payChannel,
            'serialNo'    => $serialNo,
            'requestData' => $requestData,
            'createdAt'   => time(),
        ]);
    }

    /**
     * 更新日志response
     * @param int $id
     * @param string $responseData
     * @return int
     */
    public static function editResponseData(int $id, string $responseData): int
    {
        return self::query()->where('id', $id)->update(['responseData' => $responseData]);
    }
}
